<template>
  <div class="con">
    <div class="contbox6_10">
      <div class="titlelist6_10">活动管理 / 单品返现</div>
      <div class="content">
        <el-form
          :inline="true"
          :model="formInline"
          v-loading="listLoading"
          class="demo-form-inline"
          label-width="100px"
        >
          <div class="relus"> 活动配置说明：普通代理在商城下单购买活动商品后，其上N级可以获取按比例或固定金额的返佣活动。
           <img @click="relues" src="../../assets/images/sm.png" />
          </div>
          <div class="jibenInfo">基本信息</div>
          <div class="clearfix">
            <el-form-item label="活动名称">
              <el-input
                :disabled="disabled"
                v-model="formInline.activeName"
                placeholder="请输入活动名称"
                maxlength="30"
              ></el-input>
            </el-form-item>
            <!-- <div class="listName">活动品牌</div> -->
            <el-form-item label="活动品牌">
              <el-select
                :disabled="diss"
                v-model="formInline.Brand"
                @change="pinChange"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in optionsBrand"
                  :key="item.uid"
                  :label="item.channelName"
                  :value="item.uid"
                ></el-option> </el-select
            ></el-form-item>
            <!-- </div> -->
            <!-- <div class="lister">
            <div class="listName">活动商品</div> -->
            <el-form-item label="活动商品">
              <el-select
                multiple
                @change="
                  xingType(formInline.BrandTypeNum);
                  $forceUpdate();
                "
                v-model="formInline.BrandTypeNum"
                value-key="productName"
                placeholder="请选择"
                collapse-tags
              >
                <el-option
                
                :disabled="diss"
                  label="全选"
                  value="全选"
                  @click.native="selectAll"
                ></el-option>
                <el-option
                
                :disabled="diss"
                  v-for="item in optionsBrandTypeNum"
                  :key="item.productUid"
                  :label="item.productName"
                  :value="item.productUid"
                ></el-option> </el-select
            ></el-form-item>
            <!-- </div> -->
            <!-- <br> -->
            <el-form-item label="考核时间">
              <el-date-picker
                :disabled="disabled"
                v-model="dataTime"
                type="daterange"
                :picker-options="pickerOptions"
                value-format="yyyy-MM-dd HH:mm:ss"
                start-placeholder="开始日期"
                :default-time="['00:00:00', '23:59:59']"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <!-- <el-form-item label="奖励方式">
              <el-select
                v-model="formInline.settleType"
                
                :disabled="disabled"
                clearable
                placeholder="请选择"
              >
                <el-option label="日结" value="2"></el-option>
                <el-option label="月结" value="3"></el-option>
              </el-select>
            </el-form-item> -->
            <el-form-item label="返佣方式">
              <el-select
                :disabled="disabled"
                v-model="formInline.calcType"
                clearable
                placeholder="请选择"
              >
                <el-option label="按比例" value="0"></el-option>
                <el-option label="按金额" value="1"></el-option>
              </el-select>
            </el-form-item>
            <!-- <br> -->
            <!-- <el-form-item label="参与对象">
            <el-select
              :disabled="disabled"
              v-model="formInline.objectType"
              clearable
              placeholder="请选择"
            >
              <el-option
                v-for="item in objectType"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="选择团队" v-if="formInline.objectType == '1'">
            <el-cascader
              @remove-tag="delTag"
              ref="cascaderAddr"
              v-model="formInline.officeUids"
              :disabled="disabled"
              :options="options"
              :props="{ multiple: true, checkStrictly: true, emitPath: false }"
              clearable
            ></el-cascader>
          </el-form-item> -->
            
            <el-form-item
              label="商品单价"
              class="status"
              v-if="formInline.productUid !== ''"
              >{{ formInline.unitAmt }}元
              <!-- <p v-for="(item,i) in productListData" :key="'d'+i">
              {{item.unitAmt}}元
            </p> -->
            </el-form-item>
          </div>

          <div class="jibenInfo">规则</div>

          <div style="    float: left; width: 100%;" v-for="(item, i) in formInline.activeRuleList" :key="i">
            <div class="iptP">
              <div class="userIpt gai">
                用户单次购买&nbsp;&nbsp;&nbsp;<el-input
                  :disabled="disabled"
                  v-model="item.beginNum"
                   maxlength="9"
                   @input="value=>{item.beginNum=value.replace(/[^\d]+/g,'')}"
                  class="Addipt"
                  placeholder="请输入购买数量"
                ></el-input>
                ～
                <el-input
                maxlength="9"
                  v-model="item.endNum"
                   @input="value=>{item.endNum=value.replace(/[^\d]+/g,'')}"
                  :disabled="disabled"
                   type="number"
                  class="Addipt"
                  placeholder="请输入购买数量"
                ></el-input
                >个

                <!-- 活动有效期 -->
                <el-button
                  type="primary"
                  :disabled="disabled"
                  class="btn"
                  @click="addStandard(formInline.activeRuleList)"
                  >添加 购买奖励区间</el-button
                >
                <span
                  class="el-icon-close"
                  v-if="i !== 0"
                  :disabled="disabled"
                  @click="delStandard(formInline.activeRuleList, i)"
                ></span>
              </div>
              <!-- <div v-if="formInline.type=='1'"> -->

              <div
                v-for="(n, index) in item.activeLevelList"
                :key="index"
                class="user gai" >
                <div v-if="formInline.calcType=='0'">
                  当前用户上{{ index + 1 }}级获取返佣为商品交易额的
                  <el-input
                    v-model="n.rewardAmt"
                    :disabled="disabled"
                    maxlength="6"
                    @input="value=>{n.rewardAmt=value.replace(/^\D*(\d*(?:\.\d{0,3})?).*$/g, '$1')}"
                    class="Addipt"
                    placeholder="请输入奖励比例"
                  ></el-input>
                  %
                  <el-button
                    type="info"
                    class="btn"
                    v-if="index == 0"
                    :disabled="disabled"
                    style="background:#409EFF;border:1px solid #409EFF"
                    @click="addList(item.activeLevelList, item.activeLevelList.length+1)"
                    >添加</el-button
                  >
                  <span
                    class="el-icon-close"
                    :disabled="disabled"
                    v-if="
                      index !== 0 && index == item.activeLevelList.length - 1
                    "
                    @click="delList(item.activeLevelList, index)"
                  ></span>
                </div>
                <div v-if="formInline.calcType=='1'">
                当前用户上{{ index + 1 }}级获取返佣金额
                <el-input
                  v-model="n.singleAmt"
                  :disabled="disabled"
                  maxlength="6"
                 onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" 
                  class="Addipt"
                  placeholder="请输入奖励比例"
                ></el-input>
                元
                <el-button
                  type="info"
                  class="btn"
                  v-if="index == 0"
                  :disabled="disabled"
                  @click="addList(item.activeLevelList, item.activeLevelList.length+1)"
                  >添加</el-button
                >
                <span
                  class="el-icon-close"
                  :disabled="disabled"
                  v-if="index !== 0 && index == item.activeLevelList.length - 1"
                  @click="delList(item.activeLevelList, index)"
                ></span></div>
              </div>
            </div>
          </div>
          <div class="jibenInfo">图片配置</div>
        <div style="float: left; width: 96%; margin-left: 20px">
          <p>
            banner图：尺寸345px*140px(图片大小建议不超过1M，请至少上传1张图片，最多可配置3张）
          </p>
          <div style="margin-left: 80px; margin-top: 20px">
            <el-upload
              :class="uploadDisabled"
              :disabled="disNo"
              :action="httpurl + '/api/fileUpload'"
              list-type="picture-card"
              :file-list="formInline.coverPhotos"
              :on-error="handleFail"
              :limit="3"
              name="file"
              accept=".jpg,.jpeg,.png,.JPG,.JPEG,.PNG"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove"
              :before-upload="beforeAvatarUpload"
              :on-success="success"
            >
              <i class="el-icon-plus"></i>
            </el-upload>
            <el-dialog :visible.sync="dialogVisible">
              <img width="100%" :src="dialogImageUrl" alt="" />
            </el-dialog>
          </div>
        </div>
        <div
          style="float: left; width: 96%; margin-left: 20px; margin-top: 20px"
        >
          <p>
            活动详情图：（图片大小建议不超过1M，请至少上传1张图片，最多可配置3张）
          </p>
          <div style="margin-left: 80px; margin-top: 20px">
            <el-upload
              :class="uploadDisableds"
              :disabled="disNo"
              :action="httpurl + '/api/fileUpload'"
              list-type="picture-card"
              :file-list="formInline.bgPhotos"
              :limit="3"
              name="file"
              :on-error="handleFail"
              :before-upload="beforeAvatarUpload1"
              accept=".jpg,.jpeg,.png,.JPG,.JPEG,.PNG"
              :on-preview="handlePictureCardPreview1"
              :on-remove="handleRemove1"
              :on-success="success1"
            >
              <i class="el-icon-plus"></i> </el-upload
            ><el-dialog :visible.sync="dialogVisible1">
              <img width="100%" :src="dialogImageUrl1" alt="" />
            </el-dialog>
          </div>
        </div>
          <!-- <p class="jibenInfo">备注</p>
          <el-input
            type="textarea"
            :disabled="disabled"
            class="textarea"
            maxlength="100"
            placeholder="请输入活动规则描述"
            v-model="formInline.activeDesc"
          ></el-input> -->
        </el-form>

        <div class="primary">
          <el-button
            type="primary"
            v-if="!disabled"
            @click="fromData"
            :loading="loading"
            class="primaryIpt"
            >完成</el-button
          >
          <el-button
           v-if="!disabled"
          @click="back"
            class="primaryIpt"
            >取消</el-button
          >
           <el-button
           v-if="disabled"
          @click="back"
            class="primaryIpt"
            >返回</el-button
          >
        </div>
      </div>
    </div>
    <el-dialog
      title="规则说明"
      :visible.sync="dialogVisible3"
      width="800px"
      :before-close="handleClose"
    >
      <el-row>
        <el-form label-width="100px">
          <el-form-item label="活动说明：">普通代理在商城下单购买活动商品后，当前角色的上N级可以获取一定比例或固定金额的返佣活动。活动只对选定品牌的商品进行交易量统计。</el-form-item>
          <el-form-item label="考核时间：">考核时间是活动总时间;普通代理参与的单品返现活动有效期起止时间。</el-form-item>
          <el-form-item label="奖励规则：">如按照固定金额返佣，只要满足单次购买的商品数量区间即返佣;如按照比例返佣，需要按照单次购买商品数量实际支付的总额乘以百分比算得应奖励金额修改活动<br/>如创建单条规则，则按照完成单条奖励，只奖励一次;<br/>如创建多条规则，完成哪条规则给予相应奖励，可奖励多次。</el-form-item>
          <el-form-item label="奖励方式：">实时入账。</el-form-item>
        </el-form>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible3 = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import bus from "../../assets/js/bus";
import https from "../../plugins/https.js";
import { Littlehow } from "../../assets/js/util";
import axios from "axios";
export default {
  props: {},
  data() {
    return {
      loading:false,
      uploadDisableds:"",
      uploadDisabled:"",
      diss:false,
      dialogVisible3:false,
      objectType: [
        { label: "个人", value: "0" },
        { label: "团队", value: "1" }
      ],
       // 时间选择
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() //如果没有后面的-8.64e6就是不可以选择今天的
        }
      },
      httpurl: this.GLOBAL.httpurl,
      options: [],
      formInline: {
        settleType:"",
        calcType: "0",
        productNoList: [],
        objectType: "0",
        officeUids: [],
        officeUid: localStorage.getItem("uid"),
        productUid: "",
        activeName: "",
        activeDesc: "",
        bgPhotos:[],
        coverPhotos:[],
        // channelUid: "",
        channelName: "",
        BrandType: "",
        startDate: "",
        endDate: "",
        activeRuleList: [
          {
            beginNum: "",
            endNum: "",
            activeLevelList: [{ id: "", rewardAmt: "", level: 1, singleAmt: "" }]
          }
        ]
      },
      optionsBrand: [],
      listLoading: false,
      BrandTypeList: [],
      optionsBrandTypeNum: [],
      productListData: [],
      NameList: [],
      dataTime: [],
      disabled: false,
      titleName: "",
      activeUid:""
    };
  },
  created() {
    https.getAllOfficeLista({})
      .then(res => {
        console.log(res.data.data);
        let datas = res.data.data;
        datas.map(item => {
          item.label = item.name;
          item.value = item.uid;
        });
        //  
        var format = {
          id: "uid", //菜单编号，作为树形查找id
          root: "", //顶层节点的parentId是root
          pid: "parentUid", //父节点标识字段为parentId
          child: "children", //构造出的树形子节点数组名为children
          sort: { field: "sortNo", direct: 1 }
        }; //排序字段为sortNo，且正序
        console.log(Littlehow.tree.format(datas, format));
        console.log();
        var result = Littlehow.tree.format(datas, format);
        this.options = result;
        console.log(this.options);
      })
      .catch(err => {
        // alert("洒进来的咖啡机啦");
      });
    var oemUid = localStorage.getItem("uid");
    this.activeUid=this.$route.query.activeUid?this.$route.query.activeUid:""
    if(this.$route.query.isSshow==true){
      this.disabled=true
      this.uploadDisableds = "disabled";
      this.uploadDisabled = "disabled";
    }else{
      this.disabled=false
    }
    https.queryChannelNameList({ oemUid: oemUid })
      .then(res => {
        console.log("品品牌");
        console.log(res.data.data);
        this.optionsBrand = res.data.data;
      })
      .catch(err => {
        console.log(err);
      });
      if(this.activeUid!=""){
        this.diss=true
         this.echoData()
      }
     
  },
  mounted() {},
  methods: { 
    relues() {
      this.dialogVisible3 = true;
    },
    // 上传成功
    success(res, file, fileList) {
      // 这里是element的上传地址，对应的name,url,自己打印fileList对照
      this.formInline.coverPhotos.push({ url: res.data.filePath });
      if(this.formInline.coverPhotos.length>2){
        this.uploadDisabled="disabled"
      }

    },
    // 删除图片
    handleRemove(res, file, fileList) {
      this.uploadDisabled=''
      console.log(res);
      for (var i = 0; i < this.formInline.coverPhotos.length; i++) {
        if (this.formInline.coverPhotos[i].url == res.url) {
          this.formInline.coverPhotos.splice(i, 1); //删除下标为i的元素
          return this.formInline.coverPhotos;
        }
      }
    },
    // banner图片上传前的校验
    beforeAvatarUpload(file){
      let newName = file.name.substring(file.name.lastIndexOf("."));
      const isJPG =
        file.type === "image/jpeg" ||
        file.type === "image/png" ||
        file.type === "image/jpg";
      const isLt2M = file.size / 1024 / 1024 < 1000;
      if (!isJPG) {
        // this.$message.error("上传预览图片只能是 jpg、jpeg、png 格式!");
        // return false;
        layer.open({
          content: "上传预览图片只能是 jpg、jpeg、png 格式!",
          skin: "msg",
          time: 2,
        });
        return false;
      } else {
        let that = this;
        const isSize = new Promise((resolve, reject) => {
          // const width = 345;
          // const height = 140;
          const _URL = window.URL || window.webkitURL;
          const img = new Image();
          img.onload = () => {
            let name =
              file.name.substring(0, file.name.lastIndexOf(".")) +
              "_" +
              img.width +
              "_" +
              img.height +
              newName;
            file = new File([file], name);
            const valid = this.$commit.ImageRestrictions(
              img.width,
              img.height,
              1
            );
            valid ? resolve() : reject();
          };
          img.src = _URL.createObjectURL(file);
        }).then(
          () => {
            return file;
          },
          () => {
            // this.$notify({
            //   title: "错误",
            //   message: "图片尺寸限制为345：140，大小不可超过1M",
            //   type: "error",
            // });
            layer.open({
              content: "图片尺寸限制为345：140，大小不可超过1M",
              skin: "msg",
              time: 2,
            });
            return Promise.reject();
          }
        );
        return isSize;
      }
    },
    // 详情图片上传前的校验
    beforeAvatarUpload1(file) {
      let newName = file.name.substring(file.name.lastIndexOf("."));
      const isJPG =
        file.type === "image/jpeg" ||
        file.type === "image/png" ||
        file.type === "image/jpg";
      if (!isJPG) {
        layer.open({
          content: "上传预览图片只能是 jpg、jpeg、png 格式!",
          skin: "msg",
          time: 2,
        });
        return false;
      }
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    // 上传图片
    success1(res, file, fileList) {
      // 这里是element的上传地址，对应的name,url,自己打印fileList对照
      this.formInline.bgPhotos.push({ url: res.data.filePath });
      if(this.formInline.bgPhotos.length>2){
        this.uploadDisableds="disabled"
      }
    },
    // 删除
    handleRemove1(res, file, fileList) {
      console.log(res);
      this.uploadDisableds=''
      for (var i = 0; i < this.formInline.bgPhotos.length; i++) {
        if (this.formInline.bgPhotos[i].url == res.url) {
          this.formInline.bgPhotos.splice(i, 1); //删除下标为i的元素
          return this.formInline.bgPhotos;
        }
      }
    },
    handlePictureCardPreview1(file) {
      this.dialogImageUrl1 = file.url;
      this.dialogVisible1 = true;
    },
    // 全选
    selectAll() {
      // alert(JSON.stringify(this.optionsBrandTypeNum))
      //  if (this.form.BrandTypeNum.length < this.optionsBrandTypeNum.length) {
      this.formInline.BrandTypeNum = [];
      //  alert(this.optionsBrandTypeNum.length)
      // alert(this.form.BrandTypeNum.length)
      // return
      if (
        this.formInline.BrandTypeNum.length < this.optionsBrandTypeNum.length
      ) {
        if(this.diss!=true){
        // alert("多选执行")
        var allOption = [];
        for (var i = 0; i < this.optionsBrandTypeNum.length; i++) {
          allOption.push(this.optionsBrandTypeNum[i].productUid);
        }
        this.$set(this.formInline, "BrandTypeNum", allOption);
        console.log("下面是全选以后后端需要的数据");
        console.log(this.formInline.BrandTypeNum);
        this.xingType(this.formInline.BrandTypeNum);
        this.$forceUpdate();
      } }else {
        // alert("取消多选执行")
        var allOption = [];
        this.$set(this.BrandTypeNum, "BrandTypeNum", allOption);
        this.xingType(this.formInline.BrandTypeNum);
        this.$forceUpdate();
      }
      //  alert(JSON.stringify(this.form.BrandTypeNum))
      // this.optionsBrandTypeNum.map((item) => {
      //   alert(item)
      //   this.form.BrandTypeNum.push(item.name)
      // })
      //
      //  } else {
      //    this.form.BrandTypeNum = []
      //  }
    },
    xingType(val) {
      const length = val.length;
      this.formInline.productNoList = [];
      console.log("下面是val");
      console.log(val);
      for (var i = 0; i < length; i++) {
        this.formInline.productNoList.push({
          channelUid: this.brandId,
          productUid: val[i]
        });
      }
      console.log(this.formInline.productNoList)
    },
    //请求品牌类型的接口
    pinChange(val) {
      console.log("id是");
      // this.formInline.BrandTypeNum = [];
      console.log(val);
      //品牌id
      this.brandId = val;
      var ids = this.formInline.Brand;

      //根据品牌获取商品
      https.activeBrand({ brandChannelId: val })
        .then(res => {
          console.log("这里");
          console.log(res);
          // this.BrandTypeNum = res.data.data
          this.optionsBrandTypeNum = res.data.data;
        })
        .catch(err => {
          console.log(err);
        });
    },
    queryChannelNameList() {
      let data = {
        oemUid: localStorage.getItem("uid")
      };
      https.queryChannelNameList(data).then(res => {
        if (res.data.code !== "0000") {
          this.$notify({ title: "错误", message: res.data.msg, type: "error" });
          this.listLoading = false;
          return;
        }
        this.NameList = res.data.data;
      });
    },
    // queryChannelTypeList(n, num) {
    //   num !== 1 && (this.formInline.BrandType = "");
    //   num !== 1 && (this.formInline.productUid = "");
    //   this.BrandTypeList = [];
    //   this.productListData = [];
    //   console.log(n);
    //   https.queryChannelTypeList({ channelUid: n }).then(res => {
    //     if (res.data.code !== "0000") {
    //       this.$notify({ title: "错误", message: res.data.msg, type: "error" });
    //       return;
    //     }
    //     this.BrandTypeList = res.data.data;
    //   });
    // },
    // productList(num) {
    //   if (num !== 1) this.formInline.productUid = "";
    //   this.productListData = [];
    //   if (this.formInline.BrandType == "") return;
    //   https
    //     .toChannelTypequeryProductList({
    //       channelType: this.formInline.BrandType
    //     })
    //     .then(res => {
    //       if (res.data.code !== "0000") {
    //         this.$notify({
    //           title: "错误",
    //           message: res.data.msg,
    //           type: "error"
    //         });
    //         return;
    //       }
    //       this.productListData = res.data.data;
    //     });
    // },
    echoData() {
      https.queryUpdateActive({ activeUid: this.activeUid })
        .then(res => {
          console.log("成功xxxxxx");

          console.log(res);
          this.formInline = res.data.data;
           if (this.formInline.coverPhotos.length > 2) {
            this.uploadDisabled = "disabled";
          }
          if (this.formInline.bgPhotos.length > 2) {
            this.uploadDisableds = "disabled";
          }
          // this.form.timers = [];
          this.formInline.BrandTypeNum = [];
          this.formInline.Brand = res.data.data.productNoList[0].channelUid;
          // this.form.timers.push(res.data.data.startDate);
          // this.form.timers.push(res.data.data.endDate);

          var arr = [];
          arr.push(res.data.data.startDate);
          arr.push(res.data.data.endDate);
          // this.$set(this.formInline, "timers", arr);
          this.dataTime=arr
          this.pinChange(this.formInline.Brand);
          // this.form.totalAmt = res.data.data.activeBrandOfficeTop[0].totalAmt;

          // // alert(res.data.data.activeBrandOfficeTop.length)
          // this.num = res.data.data.activeBrandOfficeTop.length + 1;
          // // alert(this.form.timers)
          // for (let i = 0; i < res.data.data.productNoList.length; i++) {
          //   // console.log(res.data.productNoList)
          //   // alert(res.data.data.productNoList[i].productUid)
          //   this.form.BrandTypeNum.push(
          //     res.data.data.productNoList[i].productUid
          //   );
          // }
          // alert(this.form.Brand)
          // this.num = res.data.data.activeBrandOfficeTop.length + 1;
          // alert(this.num)
          // this.form.productNoList.channelUid = this.form.Brand;
          https.activeBrand({
              brandChannelId: this.formInline.Brand
            })
            .then(res1 => {
              this.optionsBrandTypeNum = res1.data.data;
              console.log(this.optionsBrandTypeNum);
              var temps = [];
              //拿到数组里面的来进行赋值操作
              for (let i = 0; i < res.data.data.productNoList.length; i++) {
                // temps.push()
                temps.push(res.data.data.productNoList[i].productUid);
              }
              this.formInline.BrandTypeNum = temps;
            })
            .catch(err => {
              console.log(err);
            });
        })
        .catch(err => {
          console.log(err);
        });
      // 编辑回显
      // this.listLoading = true;
      // https.queryUpdateActive({ activeUid: this.activeUid }).then(res => {
      //   if (res.data.code !== "0000") {
      //     this.$notify({ title: "错误", message: res.data.msg, type: "error" });
      //     this.listLoading = false;
      //     return;
      //   }
      //   let n = res.data.data;

      //   if (res.data.data.activeRuleList.length == 0) {
      //     let pl = {
      //       beginNum: "",
      //       endNum: "",
      //       activeLevelList: [{ id: "", rewardAmt: "", level: 1 }]
      //     };
      //     res.data.data.activeRuleList.push(pl);
      //   }

      //   // this.formInline.BrandType = res.data.data.channelType
      //   // this.formInline.channelName = res.data.data.channelUid
      //   // this.formInline.productUid = res.data.data.productUid
      //   this.formInline = {
      //     activeUid: n.activeUid,
      //     officeUid: localStorage.getItem("uid"),
      //     productUid: n.productUid,
      //     activeName: n.activeName,
      //     activeDesc: n.activeDesc,
      //     channelUid: n.channelUid,
      //     channelName: n.channelUid,
      //     startDate: n.startDate,
      //     endDate: n.endDate,
      //     activeRuleList: n.activeRuleList,
      //     BrandType: n.channelType,
      //     unitAmt: n.unitAmt,
      //     objectType: n.objectType,
      //     officeUids: n.officeUids
      //   };
      //   this.dataTime = [n.startDate, n.endDate];
      //   this.listLoading = false;
      //   this.queryChannelTypeList(this.formInline.channelName, 1);
      //   this.productList(1);
      // });
    },
    addList(data, i) {
      debugger
      console.log(3333, i + 1);
      data.push({ id: "", rewardAmt: "", level: i++ });
    },
    delList(data, i) {
      if (this.disabled == true) return;
      data.splice(i, 1);
    },
    addStandard(data) {
      data.push({
        beginNum: "",
        endNum: "",
        activeLevelList: [{ id: "", rewardAmt: "", level: 1 }]
      });
    },
    delStandard(data, i) {
      if (this.disabled == true) return;
      data.splice(i, 1);
    },
    fromData() {
      this.loading=true
      if (this.dataTime === null) this.dataTime = [];
      this.formInline.startDate = this.dataTime[0];
      this.formInline.endDate = this.dataTime[1];
      if (this.formInline.activeName === "")
        return layer.open({
            content: "活动名称不能为空",
            skin: "msg",
            time:  2 //1秒后自动关闭
          });
       if(this.formInline.Brand==""){
        return layer.open({
          content: "活动品牌不能为空",
          skin: "msg",
          time:  2 //1秒后自动关闭
        });
      }
      if(this.dataTime.length==0){
        return layer.open({
          content: "考核时间不能为空",
          skin: "msg",
          time:  2 //1秒后自动关闭
        });
      }
      if(this.formInline.productNoList.length==0){
        return layer.open({
          content: "活动商品不能为空",
          skin: "msg",
          time:  2 //1秒后自动关闭
        });
      }
      if(this.formInline.calcType==""){
        return layer.open({
          content: "返佣方式不能为空",
          skin: "msg",
          time:  2 //1秒后自动关闭
        });
      }
      if(this.formInline.coverPhotos.length<=0){
        return layer.open({
          content: "至少上传一张banner图",
          skin: "msg",
          time:  2 //2秒后自动关闭
        })
      }
      if(this.formInline.bgPhotos.length<=0){
        return layer.open({
          content: "至少上传一张详情图",
          skin: "msg",
          time:  2 //2秒后自动关闭
        })
      }
      // if (this.dataTime.length < 1)
      //   return this.$notify({
      //     title: "错误",
      //     message: "请输入活动考核期",
      //     type: "error"
      //   });
      // if (this.formInline.activeDesc === "")
      //   return this.$notify({
      //     title: "错误",
      //     message: "请输入规则描述",
      //     type: "error"
      //   });
      // let data = this.formInline.activeRuleList;
      // for (let i = 0; i < data.length; i++) {
      //   if (data[i].beginNum === "" || data[i].endNum == "")
      //     return this.$notify({
      //       title: "错误",
      //       message: "请输入购买数量",
      //       type: "error"
      //     });
      //   if (+data[i].beginNum < 1 || +data[i].endNum < 1)
      //     return this.$notify({
      //       title: "错误",
      //       message: "请输入正确购买数量",
      //       type: "error"
      //     });
      //   for (let j = 0; j < data[i].activeLevelList.length; j++) {
      //     data[i].activeLevelList[j].level = j + 1;
      //     if (data[i].activeLevelList[j].rewardAmt === "")
      //       return this.$notify({
      //         title: "错误",
      //         message: "请输入奖励比例",
      //         type: "error"
      //       });
        //   if (+data[i].activeLevelList[j].rewardAmt <= 0)
        //     return this.$notify({
        //       title: "错误",
        //       message: "请输入正确奖励比例",
        //       type: "error"
        //     });
        // }
      // }
      // let datafrom = this.formInline;
      // datafrom.channelUid = JSON.parse(JSON.stringify(datafrom.BrandType)); // 拷贝数组

      console.log(555, this.formInline);
      // return
      // return
      // if (this.machinesType === 1) { // 创建活动
      // this.listLoading = true;
      // https.saveProductActive(this.formInline)
        axios({
        url:'/api/active/saveProductActive',
        data:this.formInline,
        method:"post",
        timeout:1000*60*2}).then(res => {
        if (res.data.code == "0000") {
          this.loading=false
         this.$router.push("activityManagement");
        } else {
          this.loading=false
          layer.open({
            content: res.data.msg,
            skin: "msg",
            time:  2 //1秒后自动关闭
          });
        }
      });
    },
    back(){
      this.$router.push("activityManagement");
    }
  }
};
</script>
<style scoped>
.con {
  position: relative;
}
.userIpt {
  margin-bottom: 20px;
  margin-left: 20px;
}
.el-icon-close {
  font-size: 25px;
  position: relative;
  right: -10px;
  top: 5px;
  cursor: pointer;
}
.user {
  margin-bottom: 20px;
  margin-left: 20px;
  float: left;
  height: 40px;
  width: 550px;
}
.btn {
  margin-left: 14px;
}
.iptP {
  margin:  0;
  /* border: 1px solid red; */
}
.Addipt {
  width: 135px;
  margin: 0 10px;
}
.primary {
  width: 100%;
  /* border: 1px solid red; */
  text-align: center;
  margin-top: 20px;
}
.textarea {
  margin-left: 20px;
  width: 1100px;
  height: 100px;
}
/deep/ .el-textarea__inner{
  height: 100px !important;
}
.status {
  margin-left: 30px;
}
.shopList {
  width: 100%;
  /* border-bottom: 1px solid #ccc; */
  font-size: 16px;
  /* height: 20px; */
  margin-bottom: 20px;
}
.shopList2 {
  width: 100%;
  /* border-bottom: 1px solid #e7e7e7; */
  font-size: 16px;
  /* height: 20px; */
  margin: 20px 0;
}
.addP {
  font-weight: bold;
  margin: 20px 0;
}
/deep/ .el-input {
  width: 300px;
}
/deep/ .el-input .el-input__inner {
  width: 300px;
}
.clearfix:after {
  display: block;
  height: 0;
  clear: both;
  content: ".";
  visibility: hidden;
}
/deep/ .gai .el-input__inner {
  width: 170px;
}
/deep/ .Addipt {
  width: 163px;
}
/* 单独样式 */
.contbox6_10 {
  width: 100%;
  /* margin-left: 2%; */
  /*  height: 87.5vh; */
  overflow-x: auto;
  box-sizing: border-box;
  float: left;
}
.jibenInfo {
  width: calc(100% - 40px);
  margin: 0 20px 20px;
  height: 40px;
  line-height: 40px;
  float: left;
  font-size: 18px;
}
.relus{
  width: 100%;
  height: 30px;
  line-height: 30px;
  padding-left: 20px;
  background: #f9f4f7;
  /* color: #FB932B; */
}
img{
  width: 16px;
  height: 16px;
}
/deep/ .el-tag__close {
  display: none !important;
}
</style>
<style>
.disabled .el-upload--picture-card {
  display: none;
}
</style>